(function () {
	angular
	.module('ydApp.doc')
	.config(function ($stateProvider) {
		$stateProvider.state('find-doc', {
			url: '/find-doc',
			controller: "findDocCtrl",
			templateUrl: 'views/docs/find-doc.html'
		});
	})
	.controller("findDocCtrl", findDocCtrl);

	function findDocCtrl ($scope, $state, xhr) {
		var vm = $scope.vm = {};
		vm.search = function (evt) {
			if (evt.keyCode == 13 && vm.keyword) {
				vm.toList({keyword: vm.keyword});
			}
		}
		vm.hotSearch = function (keyword) {
			vm.toList({keyword: keyword});
		}
		vm.departSearch = function (branchId) {
			vm.toList({branchId: branchId});
		}
		vm.toList = function (param) {
			$state.go("doc-list", param);
		}
		xhr.get("HealthInquiry/com/disease/findByCondition", {
			isCommon: 1,
			size: 12,
			sortField: 'orderNo'
		}).then(function (res) {
			if (res.successful) {
				vm.cyDeparts = res.data;
			}
		})
		xhr.get("HealthInquiry/com/branch/findByCondition", {
			pageIndex: 0,
			pageSize: 100
		}).then(function (res) {
			if (res.successful) {
				vm.departs = res.data;
			}
		})
	}
})();